package com.edu.web.servlet;

import com.edu.entity.User;
import com.edu.service.Impl.UserServiceImpl;
import com.edu.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/myServlet")
public class myServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String userName=req.getParameter("userName");
        String userPW=req.getParameter("userPW");
        System.out.println(userName+userPW);
        UserService userService=new UserServiceImpl();
        User user=userService.select(userName,userPW);
        if(user==null){
            req.setAttribute("msg","账号不存在");
            req.getRequestDispatcher("login.jsp").forward(req,resp);
            return;
        }else if (user.getUserId()==-1){
            req.setAttribute("msg","密码错误");
            req.getRequestDispatcher("login.jsp").forward(req,resp);
            return;
        }else{
            req.getSession().setAttribute("user",user);
            req.getRequestDispatcher("LoadServlet").forward(req,resp);
        }
    }
}
